package com.zhongmeng.rxjava2test.utils


import com.zhongmeng.rxjava2test.base.BaseModle

import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers

/**
 * author :rcw.
 * date :2017/10/24 10:03.
 */

object DisposableUtils {
    fun <T> getDisposable(observable: Observable<T>, which: Int, onRequestListener: BaseModle.OnRequestListener<T>): Disposable {
        return observable
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe({ data ->
                    onRequestListener?.onRequestSuccess(data, which)
                }) { throwable ->
                    onRequestListener?.onRequestFail(throwable)
                }
    }
}
